package com.own.business.question.entity.map;

import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.own.business.question.common.base.ReplyEnvironment;
import com.own.business.question.common.handler.ReplyEnvironmentHandler;
import com.own.business.question.common.serializer.ReplyEnvironmentSerializer;
import com.own.business.question.entity.po.Practice;
import com.own.component.common.base.entity.BaseMap;
import com.own.component.common.util.DateUtil;
import com.own.constant.ConstantBeanSuffix;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * PracticeMapVo
 *
 * @author 陈学礼 （你是一段成熟的代码，要学会自己改bug）
 * @version 4.0.0
 * @date 2021/05/14 15:49:28
 * @since 4.0.0
 */
@Schema(description = "练习表" + ConstantBeanSuffix.MAP_VO)
@Getter
@Setter
@ToString
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
public class PracticeMapVo extends BaseMap<Practice> {

    @Schema(description = "目标内容id")
    private Long targetId;

    @Schema(description = "用户id")
    private Long userId;

    @Schema(description = "题目数量")
    private Integer questionNumber;

    @Schema(description = "作答环境")
    @TableField(typeHandler = ReplyEnvironmentHandler.class)
    @JsonSerialize(using = ReplyEnvironmentSerializer.class)
    private ReplyEnvironment replyEnvironment;

    @Schema(description = "作答状态 0=未作答 1=已作答 2=保存 3=废弃")
    private Integer status;

    @Schema(description = "用时（ms）")
    private Long useTime;

    @Schema(description = "分数")
    private BigDecimal score;

    @Schema(description = "获取练习的时间")
    @JsonFormat(pattern = DateUtil.Pattern.DATETIME, timezone = "GMT+8")
    private LocalDateTime refreshTime;

    @Schema(description = "提交练习的时间")
    @JsonFormat(pattern = DateUtil.Pattern.DATETIME, timezone = "GMT+8")
    private LocalDateTime submitTime;

    /**
     * 构造方法
     *
     * @param entity 原对象
     */
    public PracticeMapVo(@NonNull Practice entity) {
        super(entity);
        this.targetId = entity.getFkTargetId();
        this.userId = entity.getFkUserId();
        this.questionNumber = entity.getQuestionNumber();
        this.replyEnvironment = entity.getReplyEnvironment();
        this.status = entity.getStatus();
        this.useTime = entity.getUseTime();
        this.score = entity.getScore();
        this.refreshTime = entity.getRefreshTime();
        this.submitTime = entity.getSubmitTime();
    }
}
